#!/usr/bin/python
# -*- coding: UTF-8 -*-

import pymysql
import re

coon = pymysql.connect(
    host = '49.234.81.253',user = 'root',passwd = 'liuyanjie',
    port = 3306,db = 'rdshare',charset = 'utf8'
)
cur = coon.cursor()  #建立游标
cur.execute("select * from mf_face")  #查询数据
res = cur.fetchall()    #获取结果

#duqu
with open("./MF_S01E24_1.log") as f:
    i=1
    line = f.readline()
    while line:
        if len(line)<20: 
            continue
        str = re.split("\/|\.|\_|\,", line)
        frame_id = str[5]
        person = str[7]
        sql = "select person from mf_face where frame_id = %s"%frame_id
        cur.execute(sql)  #查询数据
        res = cur.fetchall()    #获取结果
        if len(res)!=0:
            if person!="no" and res[0][0]=="0":
                sql = "update mf_face set person = 1 where frame_id = %s"%frame_id
        else:
            if person=="no":
                state=0
            else:
                state=1    
            sql = "insert into mf_face(frame_id,person) VALUE ('%s',%s);"%(frame_id,state)
    	cur.execute(sql)
    	coon.commit()
    	i=i+1
    	line = f.readline()



cur.close()     #关闭游标
coon.close()    #关闭连接
